﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Efcore_Test.Migrations
{
    /// <inheritdoc />
    public partial class project3 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_T_Leave_User_ApproverId",
                table: "T_Leave");

            migrationBuilder.DropForeignKey(
                name: "FK_T_Leave_User_RequesterId",
                table: "T_Leave");

            migrationBuilder.DropPrimaryKey(
                name: "PK_User",
                table: "User");

            migrationBuilder.RenameTable(
                name: "User",
                newName: "users");

            migrationBuilder.AddPrimaryKey(
                name: "PK_users",
                table: "users",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "T_OrgUnit",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ParentId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_OrgUnit", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_OrgUnit_T_OrgUnit_ParentId",
                        column: x => x.ParentId,
                        principalTable: "T_OrgUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_T_OrgUnit_ParentId",
                table: "T_OrgUnit",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Leave_users_ApproverId",
                table: "T_Leave",
                column: "ApproverId",
                principalTable: "users",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Leave_users_RequesterId",
                table: "T_Leave",
                column: "RequesterId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_T_Leave_users_ApproverId",
                table: "T_Leave");

            migrationBuilder.DropForeignKey(
                name: "FK_T_Leave_users_RequesterId",
                table: "T_Leave");

            migrationBuilder.DropTable(
                name: "T_OrgUnit");

            migrationBuilder.DropPrimaryKey(
                name: "PK_users",
                table: "users");

            migrationBuilder.RenameTable(
                name: "users",
                newName: "User");

            migrationBuilder.AddPrimaryKey(
                name: "PK_User",
                table: "User",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Leave_User_ApproverId",
                table: "T_Leave",
                column: "ApproverId",
                principalTable: "User",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Leave_User_RequesterId",
                table: "T_Leave",
                column: "RequesterId",
                principalTable: "User",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
